<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="品牌" prop="brandName">
        <el-input v-model="queryParams.brandName" placeholder="请输入品牌名称" clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号" prop="modelName">
        <el-input v-model="queryParams.modelName" placeholder="请输入型号名称" clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="MAC" prop="mac">
        <el-input v-model="queryParams.mac" placeholder="请输入MAC" clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构" prop="tenantName">
        <el-input v-model="queryParams.tenantName" placeholder="请输入机构名称" clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <!--TODO 添加按钮权限-->
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!--        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"-->
        <!--          v-hasPermi="['sys-enterprise:add']">新增</el-button>-->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list" ref="table">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="品牌" align="center" prop="brandName"/>
      <el-table-column label="型号" align="center" prop="modelName"/>
      <el-table-column label="设备MAC" align="center" prop="mac"/>
      <el-table-column label="所在机构" align="center" prop="tenantName"/>
      <el-table-column label="关联房间" align="center" prop="houseAddress"/>
      <el-table-column label="机构状态" align="center" prop="tenantStatus">
        <template slot-scope="scope">
          <span>{{ tenantStatusMap[scope.row.tenantStatus]? tenantStatusMap[scope.row.tenantStatus] : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备状态" align="center" prop="lockState">
        <template slot-scope="scope">
          <span>{{ lockStateMap[scope.row.lockState]? lockStateMap[scope.row.lockState] : '' }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
  </div>
</template>

<script>
import { listHouseLock } from '@/api/lock/houseLock'

export default {
  name: 'smartlock-list',
  dicts: [],
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brandName: '',
        modelName: '',
        mac: '',
        tenantName: ''
      },
      // 表单参数
      form: {},
      id: undefined,
      // 锁状态映射
      lockStateMap:{
        '1': '正常',
        '2': '冻结',
      },
      // 机构状态映射
      tenantStatusMap: {
        '0': '禁用',
        '1': '启用',
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true
      listHouseLock(this.queryParams)
        .then((response) => {
          this.list = response.rows
          this.total = response.total
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
  }
}
</script>
<style lang="scss" scoped>
.info {
  padding: 10px 15px;
  margin: 15px 0;
  background: #e6f7ff;
  color: #1890ff;

  span {
    color: #565c5f;
  }

  .clear {
    margin-left: 20px;
    cursor: pointer;
  }
}
</style>
